<?php
namespace app\api\validate;
use think\Validate;

class Index extends Validate
{
    protected $rule = [
        'method'        =>  'require|in:username,brand,product,customer,tasklist,all_customer',
        'type'          =>  'require|in:brand,video',
        'fields'        =>  'require|checkFields',
    ];

    protected $message = [
        'method.require'    => '方法参数不能为空!',
        'method.in'         => '方法参数错误!',
        'type.require'      => '方法参数不能为空!',
        'type.in'           => '方法参数错误!',
        'fields.require'    => '自定义列不能为空!',
    ];

    protected $scene = [
        'options'       =>  ['method'],
        'board'         =>  ['type'],
        'list'          =>  ['fields'],    
    ];
    
    protected function checkFields($value,$rule,$data)
    {
        $arr = explode(',',$value);
        if(!in_array('stat_cost',$arr)){
            return '自定义列消耗字段必选!';    
        }
        $all = ['total_play','valid_play','valid_play_cost','valid_play_rate','average_play_time_per_play','play_over','play_over_rate','play_duration_2s_rate',
                'play_duration_3s_rate','play_duration_5s_rate','play_duration_10s_rate','dy_like','dy_comment','dy_share','dislike_cnt','report_cnt','play_25_feed_break_rate',
                'play_50_feed_break_rate','play_75_feed_break_rate','play_99_feed_break_rate','luban_live_enter_cnt','luban_live_follow_cnt','luban_live_slidecart_click_cnt','dy_follow',
                'message_action','dy_home_visited','click_landing_page','stat_cost','show_cnt','cpm_platform','click_cnt','ctr','cpc_platform','convert_cnt','conversion_cost','conversion_rate',
                'deep_convert_cnt','deep_convert_cost','deep_convert_rate','convert_show_rate'];
        $diff = array_diff($arr, $all);
        if(!empty($diff)){
            return '自定义列字段参数错误!';
        }
        return true;
    }
}